import React from 'react'
import { fromJS } from 'immutable'
import * as constants from './constants'

const changeWidthTf = (val) => ({ // 页面宽度状态
  type: constants.CHANGE_WIDTH_TF,
  val,
})
const bookList = (list) =>({
  type: constants.GET_BOOK_LIST,
  list: fromJS(list),
})
const getBookList = (page=1,size=8) => { // 书籍列表请求
  return async (dispatch) => {
    try {
      const res = await React.$api.get('/api/book/bookList',{page,perPage:size})
      if(res.success) {
        dispatch(bookList(res.data))
      }
    } catch (err) {
      console.log(err)
    }
  }
}

export {
  changeWidthTf,
  getBookList,
}
